package edu.pku.sei.transformation.editor.model.execution;

import edu.pku.sei.modeler.model.core.MetaModelElement;

public class ObjectFlow extends Edge {
	public INode getSource() {
		return (INode) sourceElement;
	}

	public void setSource(INode source) {
		if (source instanceof MetaModelElement)
			this.sourceElement = (MetaModelElement)source;
	}

	public INode getTarget() {
		return (INode) targetElement;
	}

	public void setTarget(INode target) {
		if (target instanceof MetaModelElement)
			this.targetElement = (MetaModelElement)target;
	}
	//TODO check if source end can convert to target end
	public boolean check() {
		if (sourceElement instanceof Model && targetElement instanceof Pin) {
			Model m = (Model) sourceElement;
			Pin p = (Pin) targetElement;
			if (m.getMetamodel() == p.getFormalParameter().getType()) {
				return true;
			} else {
				return false;
			}
		} else if (sourceElement instanceof Pin && targetElement instanceof Model) {
			Model m = (Model) targetElement;
			Pin p = (Pin) sourceElement;
			if (m.getMetamodel() == p.getFormalParameter().getType()) {
				return true;
			} else {
				return false;
			}
		} else if (sourceElement instanceof Model && targetElement instanceof Model) { 
			Model m1 = (Model) sourceElement;
			Model m2 = (Model) targetElement;
			if (m1.getMetamodel() == m2.getMetamodel()) {
				return true;
			} else {
				return false;
			}
		} else if (sourceElement instanceof Pin && targetElement instanceof Pin) {
			Pin p1 = (Pin) sourceElement;
			Pin p2 = (Pin) targetElement;
			if (p1.getFormalParameter().getType() == p2.getFormalParameter().getType()) {
				return true;
			} else {
				return false;
			}
			
		} else {
			return true;
		}
		
	}
}
